<?php
/**
 * @package WordPress
 * @subpackage Toolbox
 */

/**
 * Make theme available for translation
 * Translations can be filed in the /languages/ directory
 * If you're building a theme based on toolbox, use a find and replace
 * to change 'toolbox' to the name of your theme in all the template files
 */

load_theme_textdomain( 'toolbox', TEMPLATEPATH . '/languages' );

date_default_timezone_set('Europe/Paris');

add_theme_support( 'post-thumbnails'); 
set_post_thumbnail_size( 468, 290,true );

$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
	require_once( $locale_file );

/**
 * Set the content width based on the theme's design and stylesheet.
 */
if ( ! isset( $content_width ) )
	$content_width = 640; /* pixels */

/**
 * This theme uses wp_nav_menu() in one location.
 */
register_nav_menus( array(
	'primary' => __( 'Primary Menu', 'toolbox' ),
) );

/**
 * Add default posts and comments RSS feed links to head
 */
add_theme_support( 'automatic-feed-links' );

/**
 * Add support for the Aside and Gallery Post Formats
 */
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

/**
 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
 */
function toolbox_page_menu_args($args) {
	$args['show_home'] = true;
	return $args;
}
add_filter( 'wp_page_menu_args', 'toolbox_page_menu_args' );

/**
 * Register widgetized area and update sidebar with default widgets
 */
function toolbox_widgets_init() {
	register_sidebar( array (
		'name' => __( 'Sidebar 1', 'toolbox' ),
		'id' => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h1 class="widget-title">',
		'after_title' => '</h1>',
	) );

	register_sidebar( array (
		'name' => __( 'Sidebar 2', 'toolbox' ),
		'id' => 'sidebar-2',
		'description' => __( 'An optional second sidebar area', 'toolbox' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h1 class="widget-title">',
		'after_title' => '</h1>',
	) );	
}
add_action( 'init', 'toolbox_widgets_init' );

function my_function_admin_bar(){
    return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');

function load_custom_scripts(){
        wp_enqueue_script( 'jquery');
		wp_enqueue_script( 'jquery-ui', get_bloginfo('template_url')."/scripts/js/jquery/js/jquery-ui.js", "jquery");
		wp_enqueue_script( 'jquery-tiptip', get_bloginfo('template_url')."/scripts/js/jquery/js/jquery-tiptip.js", "jquery");
        wp_enqueue_script( 'jquery-modal', get_bloginfo('template_url')."/scripts/js/jquery/js/jquery-simplemodal.js", "jquery");
		wp_enqueue_script( 'jquery-timepicker', get_bloginfo('template_url')."/scripts/js/jquery/js/jquery-timepicker.js", "jquery");
}
add_action('init', 'load_custom_scripts');
add_action('admin_enqueue_scripts', 'load_custom_scripts'); 

// insertion des interfaces
include_once 'interfaces/I_Persistent.php';
include_once 'interfaces/I_Reportable.php';
include_once 'interfaces/I_Commentable.php';

// insertion des classes 
include_once 'classes/Session.php';
include_once 'classes/User.php';
include_once 'classes/Mail.php';

include_once 'classes/Date.php';
include_once 'classes/PublicationFactory.php';
include_once 'classes/Publication.php';

include_once 'classes/Sport.php';
include_once 'classes/League.php';
include_once 'classes/Event.php';
include_once 'classes/Bet.php';
include_once 'classes/Comment.php';

include_once 'classes/Option.php';
include_once 'classes/UserOption.php';


// insertion de la langue courante
$currentLanguage = "EN";
include_once 'languages/'.$currentLanguage.'.php';


// ======================
// Fonction générale ne pouvant être placé dans une classe précise
// ======================

function getTranslation($pDomain, $pName){
	return $GLOBALS[$pDomain][$pName];
}

function getLanguages(){
	global $wpdb;
	return $wpdb->get_results($wpdb->prepare("SELECT * FROM languages"));	
}

function getSports(){
	global $wpdb;
	return $wpdb->get_results($wpdb->prepare("SELECT * FROM sports"));	
}

function getCountBetsAvailable(){
	global $wpdb;
	return $wpdb->get_var(
			$wpdb->prepare("SELECT count(*) 
							FROM bets b 
							JOIN events e 
								ON b.fk_event = e.id 								
							WHERE 	( e.startdate > '".date("Y-m-d")."')
							OR 		( e.startdate = '".date("Y-m-d")."' AND e.starthour > '".date("H:i:s")."')"));
}